// JavaScript Document
function getInternetExplorerVersion()
{
  var rv = -1; // Return value assumes failure.
  if (navigator.appName == 'Microsoft Internet Explorer')
  {
    var ua = navigator.userAgent;
    var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
    if (re.exec(ua) != null)
      rv = parseFloat( RegExp.$1 );
  }
  return rv;
}
function ShowString(str, len)
{
	if(str.length > len)
		return str.substr(0, len) + "...";
	return str;
}

function partMonney(str)
{	
	if (window.ActiveXObject)
		if(getInternetExplorerVersion() == 6 || getInternetExplorerVersion() == 7)
			return str;
    str = str.replace(".", "");
    str = str.replace(".", "");
    str = str.replace(".", "");
    str = str.replace(".", ""); 
    str = str.replace(".", "");
    str = str.replace(".", "");
    str = str.replace(".", "");
    str = str.replace(".", ""); 
    str = str.replace(".", "");            
	var j = 0;
	var temp = "";
	var result = "";
	for(var i = str.length - 1; i >= 0; i--)
	{		
		if(j==3)
		{
			temp = "." + temp;
			result = temp + result;
			j = 0;
			temp = "";
		}
		temp = str[i] + temp;
		j++;
		if(i == 0)
		{
			result = temp + result;
		}		
	}
	return result;
}
function coverMonneyToString(str)
{
	if (window.ActiveXObject)
		if(getInternetExplorerVersion() == 6 || getInternetExplorerVersion() == 7)
			return str;
	if(CheckNumber(str) == 0)
		return;
	var j = 1;
	var temp = "";
	var u = "Đồng";
	var result = "";
	for(var i = str.length - 1; i >= 0; i--)
	{
		temp = str[i] + temp; j++;
		if(u != "Tỷ" && (j == 4 || i == 0))
		{
			if(parseInt(temp) != 0)
				result = "<b>" + temp + "</b> " + u + " " + result;
			temp = ""; j = 1;
			if(u == "Đồng")
				u = "Ngàn";
			else if(u == "Ngàn")
				u = "Triệu";
			else if(u == "Triệu")
				u = "Tỷ";
		}
		else if(i == 0)
			result = "<b>" + temp + "</b> " + u + " " + result;
	}
    //document.getElementById('vcost').value = result;
	return result;
}
function CheckNumber(str)
{		
	if (window.ActiveXObject && getInternetExplorerVersion() == 6)
		return 1;
	for(var i = 0;i < str.length;i++)
		if(str[i] != '0' && str[i] != '1' && str[i] != '2' && str[i] != '3' && str[i] != '4' && str[i] != '5' && str[i] != '6' && str[i] != '7' && str[i] != '8' && str[i] != '9' && str[i] != '.')
			return 0;
	return 1;
}